package vn.mobiistar.videoapp.other;

import java.io.File;
import java.util.ArrayList;

import vn.mobiistar.videoapp.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

public class VideoAdapter extends BaseAdapter {

	private ArrayList<Video> mData;
	private Context mContext;
	private ListView mListview;

	public VideoAdapter(Context context, ArrayList<Video> data, ListView lv) {
		mContext = context;
		mData = data;
		mListview = lv;
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	// (int position, View convertView, ViewGroup parent)
	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi;
			vi = LayoutInflater.from(mContext);
			v = vi.inflate(R.layout.video_item, null);

		}
		TextView name = (TextView) v.findViewById(R.id.vi_name);
		TextView cate = (TextView) v.findViewById(R.id.vi_category);
		TextView dura = (TextView) v.findViewById(R.id.vi_duration);
		TextView view = (TextView) v.findViewById(R.id.vi_view);
		ImageView thumb = (ImageView) v.findViewById(R.id.vi_thumb);

		String tmp = mData.get(arg0).getName();
		if (tmp.length() >= 35)
			tmp = (String) tmp.subSequence(0, 34) + "...";
		name.setText(tmp);

		cate.setText(mData.get(arg0).getCatName());
		dura.setText(mData.get(arg0).getDurationString());
		view.setText(mData.get(arg0).getYoutubeViewed() + " "
				+ mContext.getResources().getString(R.string.text_viewed));
		String url = mData.get(arg0).getThumnallUrl();
		Log.v("image url",url);
		ImageLoad.display(url, thumb);

		return v;
	}

}
